package cn.gson.crmdemo.controller.finance;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

import cn.gson.crmdemo.model.pojo.Invoice;
import cn.gson.crmdemo.model.service.InvoiceService;
import cn.gson.crmdemo.model.vo.FpVo;

@Controller
public class FpController {
	@Autowired
	InvoiceService is;
	@RequestMapping("fp")
	@ResponseBody
	public Map<String,Object>fkfp(Integer pageNum,Integer pasgeSize,String invoiceDate,String invoiceNo,Integer invoiceSfhk){
		//分页
		System.err.println("321"+invoiceDate);
		Page<Object> page = PageHelper.startPage(pageNum,pasgeSize);
		//查询数据
		JSONArray selectfkfp=is.selectfp(invoiceDate,invoiceNo,invoiceSfhk);
		//创建Map集合
		return this.yy(selectfkfp, page);
	}
	//添加发票
	@RequestMapping("addfp_fpjl")
	public String addfp(FpVo fo){
		is.addfp(fo);
		return"redirect:hkjl?pageNum=1&pasgeSize=7";
	}
	//根据时间模糊查询
	@RequestMapping("fp-sjmhcx")
	@ResponseBody
	public Map<String,Object>selectsj(Integer pageNum,Integer pasgeSize,String rq){
		//分页
		Page<Object> page = PageHelper.startPage(pageNum,pasgeSize);
		//查询数据
		JSONArray selectfkfp=is.selectsj("%"+rq+"%");
		//创建Map集合
		return this.yy(selectfkfp, page);
		
	}
	//根据发票号模糊查询
		@RequestMapping("fp-fph")
		@ResponseBody
		public Map<String,Object>selectfph(Integer pageNum,Integer pasgeSize,String fph){
			//分页
			Page<Object> page = PageHelper.startPage(pageNum,pasgeSize);
			//查询数据
			JSONArray selectfkfp=is.selectfph("%"+fph+"%");
			return this.yy(selectfkfp, page);
		}
		
		//付款方式查询
		@RequestMapping("fp-fkfs")
		@ResponseBody
		public Map<String,Object>selectfs(Integer pageNum,Integer pasgeSize,Integer t){
			//分页
			Page<Object> page = PageHelper.startPage(pageNum,pasgeSize);
			//查询数据
			JSONArray selectfkfp=is.selectfs(t);
			//创建Map集合
			return this.yy(selectfkfp, page);
			
		}
		public Map<String,Object> yy(JSONArray selectfkfp,Page page) {
			Map<String, Object> map=new HashMap<String,Object>();
			map.put("list",selectfkfp);
			map.put("total",page.getTotal());
			return map;
		}
		
	}

